package com.example.bms.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.example.bms.order.feign.Storehousefeign;
import com.example.bms.order.feign.Userfeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.bms.order.entity.OrderEntity;
import com.example.bms.order.service.OrderService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;

import javax.annotation.Resource;


/**
 * @author Jiang
 * @email 337262603@qq.com
 * @date 2022-01-29 23:12:39
 */
@RestController
@RequestMapping("order/order")
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Resource
    private Userfeign userfeign;

    @Resource
    private Storehousefeign storehousefeign;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:order:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{oid}")
    //@RequiresPermissions("order:order:info")
    public R info(@PathVariable("oid") String oid) {
        OrderEntity order = orderService.getById(oid);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order) {
        orderService.save(order);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order) {
        orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public R delete(@RequestBody String[] oids) {
        orderService.removeByIds(Arrays.asList(oids));
        return R.ok();
    }

    @RequestMapping("/userlist")
    public R userlist(@RequestParam Map<String, Object> params) {
        return userfeign.userlist(params);
    }

    @RequestMapping("/stafflist")
    public R stafflist(@RequestParam Map<String, Object> params) {
        return userfeign.stafflist(params);
    }

    @RequestMapping("/waterlist")
    public R waterlist(@RequestParam Map<String, Object> params) {
        return storehousefeign.waterlist(params);
    }

}
